//
//  Explosion.swift
//  ShapeSurvival
//
//  Created by Jerry H on 1/14/15.
//  Copyright (c) 2015 HeylmunProgramming. All rights reserved.
//

import Foundation; import SpriteKit; import Darwin

class Explosion: SKSpriteNode {
    var type = 0; // 0 hurts player. 1 hurts everything // 2 missle explosion
    var finished = false
    var explosionLength: CGFloat = 0.00
    var growingToSize: CGFloat = 0.00
    var startTime: CGFloat = 0.00
    
    func setUp(Etype: Int, length: CGFloat, size: CGFloat, point: CGPoint){
        type = Etype
        explosionLength = length
        growingToSize = size
        self.position.x = point.x
        self.position.y = point.y
        self.xScale = 1.0
        self.yScale = 1.0
        self.runAction(SKAction.scaleTo(0.00, duration: 0.00))
        eManager.futureExplosions.append(self)
    }
    
    func startExplosion(Scene: GameScene){
        eManager.currentExplosions.append(self)
        //Scene.addChild(self)
        playScene.addChild(self)
        self.runAction(SKAction.scaleTo(growingToSize, duration: CFTimeInterval(explosionLength)), completion:
            {
                self.finished = true
                self.runAction(SKAction.fadeAlphaTo(0.00, duration: CFTimeInterval(0.2 * self.explosionLength)), completion:
                    {
                        let tempE = find(eManager.currentExplosions, self)
                        var setE = -1
                        if(tempE? != nil){
                            setE = Int(tempE!)
                        }
                        eManager.currentExplosions.removeAtIndex(setE)
                        self.removeFromParent()
                    } )
            }
        )
    }
    
    
    
    
    
}
